#!/bin/bash

# 停止并删除旧容器（如果存在）
echo "停止并删除旧的 nginx 容器..."
docker stop nginx 2>/dev/null
docker rm nginx 2>/dev/null

# 启动新的 nginx 容器
echo "启动新的 nginx 容器..."
docker run -d \
  --name nginx \
  --restart=unless-stopped \
  -p 9002:80 \
  -p 9003:8086 \
  -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v /home/nginx/log:/var/log/nginx \
  -v /www/work/project-vue/farm:/usr/share/nginx/html/farm:ro \
  -v /www/work/project-vue/admin:/usr/share/nginx/html/farm-admin:ro \
  nginx:latest

# 检查容器状态
echo ""
echo "检查容器状态..."
sleep 2
docker ps | grep nginx

echo ""
echo "======================================"
echo "Nginx 容器已启动！"
echo "======================================"
echo "前台商城访问地址: http://your-ip:9002"
echo "后台管理访问地址: http://your-ip:9003"
echo "======================================"
echo ""
echo "查看日志: docker logs -f nginx"
echo "进入容器: docker exec -it nginx /bin/bash"
echo "重启容器: docker restart nginx"
echo "======================================"

